<!--   
Persistent Digital Archives and Library System (PeDALS) 
(c) 2008 - All Rights Reserved
//-->
<?php
//validation of form
//check Receive Date	
if (isset($_POST['CreateAcquisition'])){		
			if (!empty($_POST['SeriesAcquisitionReceivedDate']) and !ereg ("([0-3]{1})([0-9]{1})/([0-9]{1,2})/([0-3]{1})([0-9]{3})",$_POST['SeriesAcquisitionReceivedDate'])) {		   
			   $messageReceiveDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid date.</span>";
			   $submitFrom = 1;
				}
	//check Ingest Date	
	if (empty($_POST['SeriesAcquisitionIngestDate'])) {
		$messageIngestDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid date.</span>";	
		$submitFrom = 1;
			}
		else{		
			if (!ereg ("([0-3]{1})([0-9]{1})/([0-9]{1,2})/([0-3]{1})([0-9]{3})",$_POST['SeriesAcquisitionIngestDate'])) {		   
			   $messageIngestDate = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a valid date.</span>";
			   $submitFrom = 1;
				}
			}
	//Directory
	if (empty($_POST['SeriesAcquisitionDirectory'])) {
		$messageDirectory = "<span style=\"padding-left:20px; position:absolute; float:right; color:red;\">Please enter a directory</span>";
		$submitFrom = 1;
		}		
	//submit FORM if validation OK
	if (!isset($submitFrom)){
		
				include 'includes/config.php'; 
			
			/*Get all the field values from user input*/
				$acqId = 0;
				$seriesId = $_POST["selectser"];
				if ($_POST["SeriesAcquisitionReceivedDate"] == "") {
					$acqReceiveDate = null;
					} else {
					$acqReceiveDate = $_POST["SeriesAcquisitionReceivedDate"];
					}
				if ($_POST["SeriesAcquisitionIngestDate"] == "") {
					$acqIngestDate = null;
					} else {
					$acqIngestDate = $_POST["SeriesAcquisitionIngestDate"];
					}		
				$acqAccNo = $_POST["SeriesAcquisitionAccessionNumber"];
				$acqAuthority = $_POST["SeriesAcquisitionTransferAuthority"];
				$acqSource = $_POST["SeriesAcquisitionSource"];
				$acqDirectory = $_POST["SeriesAcquisitionDirectory"];
				$acqGeneralNote = $_POST["SeriesAcquisitionGeneralNote"];
			
			/*Call the stored procedure that inserts data into the SeriesAcquisition table*/
				$tsql_callSP = "{call pac_CreateSeriesAcquisition( ?, ?, ?, ?, ?, ?, ?, ?, ?)}"; 
				$params = array(   
							 array($seriesId, SQLSRV_PARAM_IN),
							 array($acqReceiveDate, SQLSRV_PARAM_IN),
							 array($acqIngestDate, SQLSRV_PARAM_IN),  
							 array($acqAccNo, SQLSRV_PARAM_IN),  
							 array($acqAuthority, SQLSRV_PARAM_IN),  
							 array($acqSource, SQLSRV_PARAM_IN),  				  					 				 		 				 				 		     array($acqDirectory, SQLSRV_PARAM_IN),  	 				 
							 array($acqGeneralNote, SQLSRV_PARAM_IN),  	 				 
							 array($acqId, SQLSRV_PARAM_OUT)
						   );  				   
				$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);  
				
				//QL validation
					if(!$stmt){
						$SQLmessageError = "Acquisition was not added to database due to an error.";			
						$SQLErrorDB = print_r(sqlsrv_errors(),true);					
						}
					else{
						include("includes/serNewAcquisition.php");
						sqlsrv_close($conn);
						$_POST['SeriesAcquisitionReceivedDate'] = "";
						exit;
						}		
		}
}
?>

<?php 
include 'includes/config.php'; 
$term = urldecode(@$_GET["ser"]); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Persistent Digital Archives and Library System" />
<title>PeDALS Web Administration</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/showdesc.js"></script>
</head>
<body>
<?php include 'includes\header.php'; ?>
<div id="breadcrumb-container">
  <div id="breadcrumb"><a href="index.php" title="Home page">Home</a> / <a href="acqSummary.php" title="Acquisitions">Acquisitions</a> / Add Acquisition</div>
  <div id="breadcrumb-side"><form name="search" action="search.php"><input type="text" name="q" width="50"/><input type="submit" value="Go" /></form><a href="advSearch.php" title="Advanced Search" alt="Advanced Search">Advanced Search</a>
  </div>
  <div class="clear"></div>
</div>
<!-- 

  CONTENT

  -->
<div id="content-container">
  <!-- 
	
	SIDE COLUMN
	
	-->
  <div id="content-side">
    <ul class="link-list-vertical">
      <li><a href="acqSummary.php" title="View a list of all acquisitions in PeDALS.">List Acquisitions</a></li>
      <li><a href="acqNew.php" title="Add a new acquisition to PeDALS.">Add Acquisition</a></li>
    </ul>
  </div>
  <!-- 
	
	MAIN COLUMN
	
	-->
  <div id="content"><a name="maincontent" id="maincontent"></a>
    <h1>Add Acquisition</h1>

<?php 
//error message box 
if(isset($SQLErrorDB) && isset($SQLmessageError)){
$errorDiv = <<<__HTML_END
    <div style="padding-right:20px; font-size:16px; color:#F00;">$SQLmessageError
    <div style="cursor:pointer; color:#900; font-size: 12px;" onclick="if(document.getElementById('sqlServerErrorMessage').style.display == 'none')document.getElementById('sqlServerErrorMessage').style.display = ''; else document.getElementById('sqlServerErrorMessage').style.display = 'none';">Show error details</div>    
    <div id="sqlServerErrorMessage" style="background-color:#FFFFFF; color:#000; font-family:'Courier New', Courier, monospace; font-size:12px; border:1px solid #F00; width:100%; display:none; padding:7px;">$SQLErrorDB</div>    
    </div>
__HTML_END;
echo $errorDiv;
}
?>

<!---Core Metadata Standards Includes Start --->
<div id="div301" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\301.html'; ?></div>
<div id="div302" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\302.html'; ?></div>
<div id="div303" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\303.html'; ?></div>
<div id="div304" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\304.html'; ?></div>
<div id="div305" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\305.html'; ?></div>
<div id="div306" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\306.html'; ?></div>
<div id="div307" style="display: none; border:solid thin black; position:fixed; background-color:#fff; width:500px; margin-top:15px;"><?php include 'CoreData\307.html'; ?></div>
<!---Core Metadata Standards Includes End--->

    
<form method="POST"> 
<p><strong>Series:<br/></strong>

<?php
	$tsql = "{call PAC_GetSeries}";

	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsql);
	if( $getData === false ) {
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}

	$rowCount = 0;
	echo "<select name=\"selectser\" WIDTH=\"580\" STYLE=\"width: 580px\">";
	while (sqlsrv_fetch( $getData ))
	{
		$name = sqlsrv_get_field($getData, 0);	
		$id = sqlsrv_get_field($getData, 1);
		$provName = sqlsrv_get_field($getData, 2);
	
		echo "<option ";
		if ($term == $id) {
			echo "selected value='".$id."'>";
		} else {
				echo "value='".$id."'>";
				}
		echo $provName;
		echo " - ";
		echo $name;
		echo "</option>";

		$rowCount++;
    }	
echo "</select>";
?>

</p>

<p><strong>Accession Number</strong> (<a onclick="showhide('div302');" class="desclink">302</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
</span><br/>
<input type="text" name="SeriesAcquisitionAccessionNumber" size="90" maxlength="50" value="<?php if (isset($_POST['SeriesAcquisitionAccessionNumber'])) echo $_POST['SeriesAcquisitionAccessionNumber'];?>"></p>


<!--validation message-->
<p><strong>Date Received by Agency (MM/DD/YYYY)</strong> (<a onclick="showhide('div303');" class="desclink">303</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
	<?php //validation message
		if (isset($messageReceiveDate)) echo $messageReceiveDate;
    ?>
</span><br/>
<!--/ validation message-->
<input type="text" name="SeriesAcquisitionReceivedDate" size="10" maxlength="10" value="<?php if (isset($_POST['SeriesAcquisitionReceivedDate'])) echo $_POST['SeriesAcquisitionReceivedDate'];?>"></p>    



<p><strong>Date Submitted to PeDALS for Processing (mandatory MM/DD/YYYY)</strong> (<a onclick="showhide('div304');" class="desclink">304</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
	<?php //validation message
		if (isset($messageIngestDate)) echo $messageIngestDate;
    ?>
</span><br/>
<input type="text" name="SeriesAcquisitionIngestDate" size="10" maxlength="10" value="<?php if (isset($_POST['SeriesAcquisitionIngestDate'])) echo $_POST['SeriesAcquisitionIngestDate'];?>"></p>    

<p><strong>Transfer Authority</strong> (<a onclick="showhide('div305');" class="desclink">305</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
</span><br/>
<input type="text" name="SeriesAcquisitionTransferAuthority" size="90" maxlength="50" value="<?php if (isset($_POST['SeriesAcquisitionTransferAuthority'])) echo $_POST['SeriesAcquisitionTransferAuthority'];?>"></p>

<p><strong>Source</strong> (<a onclick="showhide('div301');" class="desclink">301</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
	<?php //validation message
		if (isset($messageSource)) echo $messageSource;
    ?>
</span><br/>
<input type="text" name="SeriesAcquisitionSource" size="90" maxlength="100" value="<?php if (isset($_POST['SeriesAcquisitionSource'])) echo $_POST['SeriesAcquisitionSource'];?>"></p>

<p><strong>General Note</strong>(<a onclick="showhide('div304');" class="desclink">304</a>)<span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;"></span><br/>
<textarea name="SeriesAcquisitionGeneralNote" rows="15" cols="65"><?php if (isset($_REQUEST['SeriesAcquisitionGeneralNote'])){echo $_REQUEST['SeriesAcquisitionGeneralNote'];}?></textarea></p>

<p><strong>File Directory (mandatory; end with "\")</strong><span style=" padding-left:0px; position:absolute; float:right; color:red; width:100%;">
	<?php //validation message
		if (isset($messageDirectory)) echo $messageDirectory;
    ?>
</span><br/>
<input type="text" name="SeriesAcquisitionDirectory" size="90" maxlength="255" value="<?php if (isset($_POST['SeriesAcquisitionDirectory'])) echo $_POST['SeriesAcquisitionDirectory'];?>"></p>

	  <input type="submit" value="submit" name="CreateAcquisition"><br />
      <input type="hidden" name="_submit_check" value="1"/> 
</form>
<!--Perform the following if user clicks on the submit button-->
<?php
if (array_key_exists('_submit_check', $_POST)) {

}

?>
<?php include 'includes\footer.php'; ?>
  </div>

</div>
</body>
</html>
